/**
 * Created by fangshufeng on 2017/7/15.
 */

import React,{Component} from 'react';
import {
    View,
    Text,
    ListView,
    Image,
    StyleSheet,
    TouchableOpacity,
    AlertIOS,
} from 'react-native';

let  data = require('./Wine.json');
let Dimensions = require('Dimensions');
let  screenwidth = Dimensions.get('window').width;


class TestListView extends  Component {

    constructor(props) {
        super(props);

        let ds = new ListView.DataSource({
            rowHasChanged: (r1, r2) => r1 !== r2,
        });
        this.state = {
            dataSource: ds.cloneWithRows(data),

        }

    }

    render() {
        return(
            <ListView
                dataSource={this.state.dataSource}
                renderRow={this.rendCell}
            />
        );
    }

    rendCell = (rowData,sectionID,rowID) => {
       return(
           <TouchableOpacity
               onPress={this.cellDidClick}
           >
           <View style={styles.cellRowStyle}>
               <Image source={require('./images/1.jpg')} style={{width:100,height: 100}}/>

               <View>
                   <Text style={styles.rowTextStyle}>{rowData.name}</Text>
                   <Text style={styles.rowTextStyle}>{rowData.money}</Text>
               </View>

           </View>
        </TouchableOpacity>
       );
    }


    cellDidClick = (rowID) => {

         AlertIOS.alert(''+rowID);
    }

}


const  styles = StyleSheet.create({
    cellRowStyle:{
        flexDirection:'row',
        borderBottomWidth:0.5,
        borderBottomColor:'gray',
    },
    rowTextStyle:{
        width:screenwidth * 0.7,
    }

});

export  default  TestListView;